import { PropsWithChildren, useEffect } from 'react';
import Taro, { useLaunch } from '@tarojs/taro';
import { Provider, useDispatch } from 'react-redux';

import 'react-loading-skeleton/dist/skeleton.css';
import '@nutui/nutui-react-taro/dist/style.css';
import './app.scss';
import './assets/font/iconfont.css';
import ReduxStore from './store/ReduxStore';
import { setCinemaCity } from './store/movieDataSlice';



const DataFetch = () => {
  const dispatch = useDispatch();
  useEffect(() => {
    Taro.request({
      url: "https://apis.netstart.cn/maoyan/cities.json",
      success: function (res) {
        console.log("调用了getCinemaCity", res.data);
        dispatch(setCinemaCity(res.data));
      },
      fail: function (err) {
        console.error('Error fetching city ID:', err);
      }
    });
  }, []);

  return null;
};

const App = ({ children }: PropsWithChildren<any>) => {
  useLaunch(() => {
    console.log('App launched.');
  });



  // children 是将要会渲染的页面
  return (
    <Provider store={ReduxStore}>
      <DataFetch />
      {children}
    </Provider>


  );
};



export default App;
